//
//  ValibleTicketCell.m
//  Shengzhuli
//
//  Created by FXGuo on 2018/2/12.
//  Copyright © 2018年 kamangkeji. All rights reserved.
//

#import "ValibleTicketCell.h"

@interface ValibleTicketCell()

@property (weak, nonatomic) IBOutlet UIImageView *logoImg;
@property (weak, nonatomic) IBOutlet UILabel *nameLab;
@property (weak, nonatomic) IBOutlet UILabel *numLab;
@property (weak, nonatomic) IBOutlet UILabel *timeLab;
@property (weak, nonatomic) IBOutlet UIButton *selectBtn;


@end

@implementation ValibleTicketCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (void)setModel:(TicketModel *)model
{
    _model = model;
    [self.logoImg sd_setImageWithURL:[NSURL URLWithString:model.ticketLogo] placeholderImage:GetImage(@"person_avatar")];
    self.nameLab.text = model.name;
    self.timeLab.text = [NSString stringWithFormat:@"优惠券使用期限：%@止",[self spToDateString:model.validateTime]];
    if ([model.type isEqualToString:@"1"]) {
        self.numLab.text = [NSString stringWithFormat:@"可用次数:%zd",model.num];
    }else if ([model.type isEqualToString:@"2"]) {
        self.numLab.text = [NSString stringWithFormat:@"可邀请人数:%zd",model.num];
    }
}


- (IBAction)selectClick:(UIButton *)btn
{
    btn.selected = !btn.selected;
    if (self.selectTicketBlock) {
        self.selectTicketBlock(self.model, btn.selected);
    }
}
- (NSString *)spToDateString:(NSString *)sp
{
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    formatter.dateFormat = @"YYYY年MM月dd日";
    
    NSDate *timeDate = [NSDate dateWithTimeIntervalSince1970:[sp floatValue]/1000];
    return [formatter stringFromDate:timeDate];
}

@end
